package com.lym.order.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;

import java.util.UUID;


/**
 * feign请求拦截器
 *
 * XTokenRequestInterceptor 生效有两种方式:
 * 1、在 application-feign.yml 文件中配置 openfeign.client.config.service-product.request-interceptors=com.lym.order.interceptor.XTokenRequestInterceptor
 * 2、使用 @Component 注册 XTokenRequestInterceptor 进容器
 */
@Component
public class XTokenRequestInterceptor implements RequestInterceptor {

    /**
     * 请求拦截器
     * @param requestTemplate 请求模板
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        System.out.println("XTokenRequestInterceptor 拦截器生效 ... ...");
        // 添加请求头X-Token
        requestTemplate.header("X-Token", UUID.randomUUID().toString());
    }

}
